@extends('layouts.userctl')
@section('content')
<style>
	.layui-card-header {
		margin-top: 15px;
	}


	.userstatus {
		margin-left: 6px;
		color: #888;
		font-size: 14px;
	}

	.layui-table-tips-c::before {
		position: absolute !important;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0px !important;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.layui-table-cell {
		height: auto !important;
	}
</style>
{{csrf_field()}}
<div class="layuimini-container">
	<div class="layuimini-main">
		<div style="margin: 10px 10px 10px 10px" id="btn">
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item">
					<div class="layui-inline" style="float: right;">
						<!--注意此处button标签里的type属性-->
						<button type="button" class="layui-btn layui-btn-normal" lay-submit id="searchbtn"
							lay-filter="data-search-btn"><i class="layui-icon layui-icon-search"></i>搜  索</button>
					</div>
					<div class="layui-inline" style="float: right;">
						<label class="layui-form-label">关键字</label>
						<div class="layui-input-inline">
							<!--注意此处input标签里的id-->
							<input class="layui-input" name="keyword" id="keywordinput">
						</div>
					</div>
					<!-- <div class="layui-inline" style="float: left;">
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增个人用户</a>
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.addcomuser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增企业用户</a>
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增政府用户</a>
					</div> -->
				</div>
			</form>
		</div>
		<!--注意此处table标签里的id-->
		<table class="layui-table layui-hide" id="dataTable" lay-filter="dataTable"></table>
	</div>
</div>

<!-- <div class="layui-card">
	<div class="layui-card-header layuiadmin-card-header-auto">
		<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}" style="color: #fff;">新增用户</a>
	</div>
	<div class="layui-card-body">
		<table id="dataTable" lay-filter="dataTable"></table>
	</div>
</div> -->

<script>
	layui.use(['layer', 'table', 'form'], function() {
		var layer = layui.layer
		var form = layui.form
		var table = layui.table
		//用户表格初始化
		var dataTable = table.render({
			elem: '#dataTable',
			height: 'full',
			limit: 10,
			url: '{{ route("admin.resident.data") }}',
			page: true,
			cols: [
				[ //表头
					{ field: 'comName', title: '户主姓名', width: 150 },
					{ field: 'idcard', title: '身份证号', width: 150 },
					{
						title: '门牌号',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.door_code
							} else {
								return ''
							}
						}
					},
					{
						title: '出生年月',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.birthday
							} else {
								return ''
							}
						}
					},
					{
						field: 'province',
						title: '省 份',
						width: 150,
						templet: function(d) {
							if (d.place_1) {
								return d.place_1.name
							} else {
								return ''
							}

						}
					},
					{
						field: 'city',
						title: '城 市',
						width: 150,
						templet: function(d) {
							if (d.place_2) {
								return d.place_2.name
							} else {
								return ''
							}

						}
					},
					{
						field: 'district',
						title: '区',
						width: 150,
						templet: function(d) {
							if (d.place_3) {
								return d.place_3.name
							} else {
								return ''
							}

						}
					},
					{
						field: 'street',
						title: '街 道',
						width: 150,
						templet: function(d) {
							if (d.place_4) {
								return d.place_4.name
							} else {
								return ''
							}

						}
					},
					{
						field: 'community',
						title: '社 区',
						width: 150,
						templet: function(d) {
							if (d.place_5) {
								return d.place_5.name
							} else {
								return ''
							}

						}
					},
					{ field: 'address', title: '详细位置', width: 150 },
					{
						title: '居住人数',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.live_people
							} else {
								return ''
							}
						}
					},
					{
						title: '居住面积',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.live_area
							} else {
								return ''
							}
						}
					},
					{
						title: '住户类型',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.live_type == 1 ? '住户' : (d.resident.live_type ==
									2 ? '租户' : '')
							} else {
								return ''
							}
						}
					},
					{
						title: '老人类型',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.old_type == 1 ? '独居老人' : (d.resident.old_type ==
									2 ? '孤寡老人' : (d.resident.old_type == 3 ? '其他' : ''))
							} else {
								return ''
							}
						}
					},
					{
						title: '燃气类型',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.fire_type == 1 ? '液化气' : (d.resident.fire_type ==
									2 ? '天然气' : (d.resident.fire_type == 3 ? '醇基燃料' : ''))
							} else {
								return ''
							}
						}
					},
					{
						title: '农田数',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.farm_num + '亩'
							} else {
								return ''
							}
						}
					},
					{
						title: '液化气钢瓶数',
						width: 150,
						templet: function(d) {
							if (d.resident) {
								return d.resident.fire_num
							} else {
								return ''
							}
						}
					},
					{
						title: '操  作',
						fixed: "right",
						width: 120,
						templet: function(d) {
							return '<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="record">学 习</a>'
						}
					}
				]
			],
			done: function(response) { //定位当前table视图
				//动态监听表头高度变化，冻结行跟着改变高度
				$('.layui-table-header  tr').resize(function() {
					$('.layui-table-header  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-header table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表头高度一致
				$('.layui-table-header  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-header table tr')[index]).height($(
						val).height())
				})

				//表体部分
				//动态监听表体高度变化，冻结行跟着改变高度
				$('.layui-table-body  tr').resize(function() {
					$('.layui-table-body  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-body table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表体高度一致
				$('.layui-table-body  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-body table tr')[index]).height($(val)
						.height())
				})
				var tableView = this.elem.next()

				//response.data获取后端返  回的JSON格式数据
				$.each(response.data, function(index, item) {

					//逻辑判断
					if (item.is_delete == '0') {
						//改变TR标签内字体颜色
						tableView.find('tbody tr[data-index="' + index + '"]').css('color',
							'#FF0033')
					}
				})
			}
		})
		$('#searchbtn').click(function() {
			dataTable.reload({
				where: { keyword: $('#keywordinput').val() },
				page: { curr: 1 }
			})
		})
		$(document).on('click', '.smimg', function() {
			var url = $(this).attr('src')
			var img = '<img src=\'' + url +
				'\' style=\'width:800px;height:auto;max-height:800px;background-color:#fff;\'/>'
			layer.open({
				type: 1,
				title: false,
				scrollbar: false,
				area: ['800px', 'auto'],
				skin: 'layui-layer-nobg', //没有背景色
				shadeClose: true,
				content: img
			})
		})
		//监听工具条
		table.on('tool(dataTable)', function(obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data //获得当前行数据
				,
				layEvent = obj.event //获得 lay-event 对应的值
			if (layEvent === 'edit') {
				location.href = '/admin/com/residentedit?id=' + data.id
			}else if (layEvent === 'record') {
				location.href = '/admin/selfWatchRecords/reportlist?id=' + data.id
			}
		})
	})
</script>
@endsection
